const { EMAIL_VERIFY_FAILED } = require('../config/error')
const cache = require('../app/cache')
const verifyEmailCode = async (ctx, next) => {
  const { emailCode, email } = ctx.request.body
  const code = cache.get(email)
  console.log(`output->emailCode,email`, emailCode, email, code)
  if (emailCode !== code) {
    return ctx.app.emit('error', EMAIL_VERIFY_FAILED, ctx)
  }
  await next()
}
module.exports = {
  verifyEmailCode
}